package Main3;
import java.util.Arrays;
import java.util.Scanner;

	interface IntegerStack{
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();

}

	 class ArrayIntegerStack implements IntegerStack{



		private Integer[] ints;
		 int top=0;
		 public int A;
		 
		 
		 public ArrayIntegerStack(int n){
			 ints=new Integer[n];
		 }
		 
		@Override
		public Integer push(Integer item) {
			if(this.size()==ints.length)
				return null;
			ints[top++]=item;
			return item;
		}

		@Override
		public Integer pop() {
			if(top==0)
			return null;
			top--;
			return ints[top];
		}
		
		@Override
		public Integer peek() {
			if(top==0)
			return null;

			return ints[top-1];
		}

		@Override
		public boolean empty() {
			if(top==0)
			return true;
			else return false;
		}

		@Override
		public int size() {
			return top;
		}
		
		 @Override
		public String toString() {
			return Arrays.toString(ints);
		}
	}
	

	
	


public class Main3 {

	public static void main(String[] args) {

		Scanner in=new Scanner(System.in 

);
		int n=Integer.parseInt(in.nextLine());
		ArrayIntegerStack ints = new ArrayIntegerStack(n);
		int m=Integer.parseInt(in.nextLine());
		for (int i = 0; i < m; i++) 
		{
			System.out.println(ints.push(in.nextInt()));
		}
		System.out.print(ints.peek() + "," + ints.empty() + "," + ints.size());
		System.out.println();
		System.out.println(ints);
		int x=in.nextInt();
		
		for (int i = 0; i < x; i++) 
		{
			System.out.println(ints.pop());
		}
		System.out.print(ints.peek() + "," + ints.empty() + "," + ints.size());
		System.out.println();
		System.out.println(ints);
	
	}

}
